//
//  HTStatusCell.swift
//  weibo
//
//  Created by JonsonLiu on 16/4/21.
//  Copyright © 2016年 liujonson. All rights reserved.
//




let HTlableFont : CGFloat = 14

let HTstatusCellFont : CGFloat = 14

let HTstatusCellMargin : CGFloat = 10

let HMStatusCellMargin: CGFloat = 8

let HTstatusCellWith : CGFloat = 35

let HTStatusCellBottomViewH: CGFloat = 35


import UIKit
import SnapKit
class HTStatusCell: UITableViewCell {
    
    var toolBarCons : Constraint?
    
    var statusViewModel : HTStatsCellViewModel?{
    
        didSet{
        
            originalView.statusViewModel = statusViewModel
            
            toolBarCons?.uninstall()
            
            if statusViewModel?.status?.retweeted_status != nil {
                
                retweetView.statusViewModel = statusViewModel
                
                retweetView.hidden = false
                
                toolBar.snp_makeConstraints(closure: { (make) -> Void in
                    
                    toolBarCons = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                
            }else{
            
                retweetView.hidden = true
                
                toolBar.snp_makeConstraints(closure: { (make) -> Void in
                    
                    toolBarCons = make.top.equalTo(originalView.snp_bottom).constraint
                })
            }
            
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    
    func setupUI(){
        
       // backgroundView = UIImageView(image: UIImage(named: "1"))
        
        selectionStyle = .None
//         backgroundColor = UIColor.blackColor()
        contentView.addSubview(originalView)
        contentView.addSubview(toolBar)
        contentView.addSubview(retweetView)
        
        
        
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(HMStatusCellMargin)
            make.leading.trailing.equalTo(contentView)
            //高度不确定写死
            //make.height.equalTo(150)
            //正文的lable要自由调动 所以要设置约束
            
        }
        
        toolBar.snp_makeConstraints { (make) -> Void in
            
            toolBarCons = make.top.equalTo(retweetView.snp_bottom).constraint
            make.leading.trailing.equalTo(originalView)
            make.height.equalTo(HTStatusCellBottomViewH)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(originalView)
            make.top.equalTo(originalView.snp_bottom)

        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(toolBar.snp_bottom)
            make.leading.top.trailing.equalTo(self)
        }
    }
    
    
    private lazy var originalView : HToriginalStatusView = HToriginalStatusView()
    
    private lazy var toolBar : HTStautsToolBar = HTStautsToolBar()
    
    //微博转发
    private lazy var retweetView : HTRetweetStatus = HTRetweetStatus()
}
